layui.define(["table", "form"], function(e) {
    var admin = layui.admin;
    var $ = layui.$,
        form = layui.form,
        table = layui.table;
    //监听搜索
    form.on('submit(LAY-info-front-search)', function(data) {
        var field = data.field;
        //执行重载
       table.reload('LAY-info-manage', {
            where: field,
            page: {curr: 1},
        });
    });
    //事件
    var active = {};
    $('.layui-btn.layuiadmin-btn-info').on('click', function() {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    //表格内处理     
    table.render({
        elem: "#LAY-info-manage",
        url: app_url + "log/listData",
        cols: [
            [{
                field: "id",
                title: "ID",
                width: 50,
            }, {
                field: "title",
                title: "用户",
            }, {
                field: "url",
                title: "网址",
            }, {
                field: "method",
                title: "方式",
            }, {
                field: "content",
                title: "参数",
                templet:function(d){
                     return JSON.stringify(d.content);
                }
            }, {
                field: "ip",
                title: "ip",
            }, {
                field: "brower",
                title: "浏览器",
            }, {
                field: "os",
                title: "系统",
            }, {
                field: "create_time",
                title: "日期",
                templet: function(d) {
                    return new Date(d.create_time * 1000).format("yyyy-MM-dd hh:mm:ss");;
                }
            }]
        ],
        page: !0,
        limit: 10,
        height: "full-80",
        text: "对不起，加载出现异常！"
    }), table.on("tool(LAY-info-manage)", function(e) {}), e("log", {})
});


Date.prototype.format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}